<?php defined('SYSPATH') or die('No direct script access.');
 
class Model_Places extends Model {

    public function getAll() {
        $sql = "select id, parent_id, title from places";
        return DB::query(Database::SELECT, $sql)->execute()->as_array();
    }

    public function getOne($id, $type) {
    	if ($type == 'country') {
    		$sql = "select country_id, name as title, description as text from country where country_id='$id'";
    	} elseif($type == 'city') {
            $sql = "select city_id, name as title, description as text from city where city_id='$id'";
        } elseif($type == 'hotel') {
            $sql = "select id, title, description as text from hotels where id='$id'";
        }
        
        return DB::query(Database::SELECT, $sql)->execute()->as_array();
    }

    public function get_countries() {
    	return DB::select(array('country_id', 'id'), 'name')
    	->from('country')
    	->as_object()
    	->execute();
    }

    public function get_cities($id) {
        return DB::select(array('city_id', 'id'), 'name')
        ->from('city')
        ->where('country_id', '=', $id)
        ->as_object()
        ->execute();
    }

    public function get_hotels($id) {
        return DB::select('id', array('title', 'name'))
        ->from('hotels')
        ->where('parent', '=', $id)
        ->as_object()
        ->execute();
    }

}